SUFFIXES = {1000:['KB','MB','GB','TB','ZB','YB'],
            1024:['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB']}

def approximate_size(size,a_kilobyte_is_1024_bytes=True):
    '''Convert a file size to human-readble from.

    keywork arguments:
    size -- file size in bytes
    a_kilobyte_is_1024_bytes -- if True (deault) ,usemultiples of 1024
    
if False,use multiples of 1000
    Returns:string
    '''
    if size<0:
        raise ValueError('number must be non-negative')
    multiple = 1024 if a_kilobyte_is_1024_bytes else 1000
    for suffix in SUFFIXES[multiple]:
        size /= multiple
        if size < multiple:
            return '{0:.1f}{1}'.format(size,suffix)
        raise ValueError('number too large')

if __name__ == '__main__':
        print('开始运行')
        print(approximate_size(4000,False))
        print(approximate_size(4000))
